home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Mac OS / Apple Shared Library Manager / ASLM Developer Tools / Interfaces / CIncludes / LibraryManagerUtilities.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-19  |  29.7 KB  |  855 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        LibraryManagerUtilities.h
  3.  
  4.     Contains:    Interface file for ASLM utilities
  5.  
  6.     Copyright:    © 1991-1995 by Apple Computer, Inc., all rights reserved.
  7.  
  8. */
  9.  
  10.  
  11. #ifndef __LIBRARYMANAGERUTILITIES__
  12. #define __LIBRARYMANAGERUTILITIES__
  13.  
  14. #ifndef __LIBRARYMANAGER__
  15. #include <LibraryManager.h>
  16. #endif
  17.  
  18. /*******************************************************************************
  19. ** Forward class declarations
  20. ********************************************************************************/
  21.  
  22. #ifdef __cplusplus
  23.     class    TNotifier;
  24.     class    TIterator;
  25.     class    TLibraryFile;
  26.     class    TClassInfo;
  27.     typedef TClassInfo    TFunctionSetInfo;
  28. #else
  29.     typedef    void    TNotifier;
  30.     typedef    void    TIterator;
  31.     typedef void    TLibraryFile;
  32.     typedef void    TFunctionSetInfo;
  33. #endif
  34.  
  35.  
  36. /*******************************************************************************
  37. ** Routines for loading and unloading the ASLM.
  38. **
  39. ** UnloadLibraryManager and LoadLibraryManager can be bad for your health! 
  40. ** They should only be used for testing purposes.
  41. ********************************************************************************/
  42.  
  43. #ifdef __cplusplus
  44.     extern "C" {
  45. #endif
  46.  
  47. Boolean    IsLibraryManagerLoaded(void);
  48. Boolean    LoadLibraryManager(void);    /* returns true if success or already loaded */
  49. void    UnloadLibraryManager(void);
  50.  
  51. /*******************************************************************************
  52. ** C Routines for allocating memory out of TMemoryPools.
  53. **
  54. ** The following routines allow C users to allocate memory from TMemoryPools.
  55. ** SLMNewOperator is used for doing allocations and SLMDeleteOperator is 
  56. ** used for freeing memory. SLMNewOperator will allocate memory out of
  57. ** the specified pool. If you pass in NULL for the pool then it will use
  58. ** default memory allocation. The default memory allocation is to allocate
  59. ** out of the the library's local pool if the library was built with
  60. ** memory=local, and out of the client's local pool if the library was built
  61. ** with memory=client. If you don't want to use default memory allocation then
  62. ** you can call GetLocalPool to get the library's local pool, and GetClientPool
  63. ** to get the current client's local pool.
  64. ********************************************************************************/
  65.  
  66. void*    SLMNewOperator(size_t, TMemoryPool*);
  67. void    SLMDeleteOperator(void*);
  68.  
  69. /*******************************************************************************
  70. ** GetSLMVersion
  71. **
  72. ** Returns the version of the installed ASLM in the 'vers'
  73. ** resource format (the first 4 bytes only). Returns 0 if the
  74. ** ASLM is not installed.
  75. ********************************************************************************/
  76.  
  77. unsigned long GetSLMVersion(void);
  78.  
  79. /*******************************************************************************
  80. ** RegisterInspector
  81. **
  82. ** Should only be used by Inspector application.
  83. ********************************************************************************/
  84.  
  85. void RegisterInspector(void*);
  86.  
  87. /*******************************************************************************
  88. ** Trace
  89. **
  90. ** Used to send output to the Trace Montior's Window.
  91. ********************************************************************************/
  92.  
  93. void Trace(const char *formatStr, ...);
  94.  
  95. /*******************************************************************************
  96. ** CallInitLibraryManager
  97. **
  98. ** CallInitLibraryManager is called automatically when an application first
  99. ** starts up. It is called before any static objects are constructed. It's
  100. ** purpose is to allow applications to call InitLibraryManager before static
  101. ** objects are constructed so they can be instances of shared classes and can also
  102. ** allocate memory using the ASLM global new operator. A default implementation
  103. ** is provided in LibraryManager.o that does nothing at all. If you want it to
  104. ** actually call InitLibraryManager, you must provide your own implementation
  105. ** that makes the InitLibraryManager call and returns the result. Make sure you
  106. ** link it in before LibraryManager.o. If anything besides kNoError is returned
  107. ** then the static objects will not be initalized. If you use this method of
  108. ** calling InitLibraryManager, then do no call CleanupLibraryManager or a crash
  109. ** will occur when the static objects are destructed. ASLM will call it
  110. ** automatically when the application quits after static object destructors
  111. ** are called.
  112. ********************************************************************************/
  113.  
  114. OSErr CallInitLibraryManager();
  115.  
  116. /*******************************************************************************
  117. ** SLMsprintf
  118. **
  119. ** The SLMsprintf routine in stdclib.o won't work with ASLM libraries.
  120. ** Use the one in LibraryManager.o instead.
  121. ********************************************************************************/
  122.  
  123. int SLMsprintf(char *outString, const char *argp, ...);                
  124. int SLMvsprintf(char* outstring, const char* format, char* args);
  125.  
  126. /*******************************************************************************
  127. ** Utility functions
  128. **
  129. ** %%% These functions need to be modified if unsigned short is not 16 bits
  130. ********************************************************************************/
  131.  
  132. #ifdef __cplusplus
  133.  
  134. inline unsigned short HighWord(unsigned long l)
  135. {
  136.     return ((unsigned short)(l >> 16));
  137. }
  138.  
  139. inline unsigned short LowWord(unsigned long l)
  140. {
  141.     return (unsigned short)l;
  142. }
  143.  
  144. inline unsigned char HighByte(unsigned short l)
  145. {
  146.     return (unsigned char)(l >> 8);
  147. }
  148.  
  149. inline unsigned char LowByte(unsigned short l)
  150. {
  151.     return (unsigned char)l;
  152. }
  153.  
  154. #else
  155.  
  156. #define HighWord(x)        ((unsigned short)((x) >> 16))
  157. #define LowWord(x)        (((unsigned short)(x)))
  158. #define HighByte(x)        ((unsigned char)((x) >> 8))
  159. #define LowByte(x)        (((unsigned char)(x)))
  160.  
  161. #endif
  162.  
  163. /*******************************************************************************
  164. ** Atomic Bit functions
  165. **
  166. ** These functions atomically set, clear, and test bits. SetBit and ClearBit
  167. ** return the previous value of the bit. AtomicSetBoolean and AtomicClearBoolean
  168. ** return true if the bit was set or cleared by the caller and false if the
  169. ** bit was already set or cleared before the caller tried to set or clear it.
  170. ********************************************************************************/
  171.  
  172. Boolean    SetBit(void* mem, size_t bitno);
  173. Boolean    ClearBit(void* mem, size_t bitno);
  174. Boolean    TestBit(const void* mem, size_t bitno);
  175.  
  176. #if USES68KINLINES
  177.  
  178.     #pragma parameter __D0 AtomicSetBoolean(__A0)
  179.     Boolean AtomicSetBoolean(unsigned char*) =
  180.     {
  181.         0x08d0, 0x00, 0x57c0, 0x0200, 0x0001    /* bset.b #0,(a0); seq d0, andi.b #$01,d0 */
  182.     };
  183.     
  184.     #pragma parameter __D0 AtomicClearBoolean(__A0)
  185.     Boolean AtomicClearBoolean(unsigned char*) =
  186.     {
  187.         0x0890, 0x00, 0x56c0, 0x0200, 0x0001    /* bclr.b #0,(a0); sne d0, andi.b #$01,d0 */
  188.     };
  189.     
  190.     #pragma parameter __D0 AtomicTestBoolean(__A0)
  191.     Boolean AtomicTestBoolean(unsigned char*) =
  192.     {
  193.         0x0810, 0x00, 0x56c0, 0x0200, 0x0001    /* btst.b #0,(a0); sne d0, andi.b #$01,d0 */
  194.     };
  195.  
  196. #else
  197.     #ifdef __cplusplus
  198.  
  199.         inline Boolean AtomicSetBoolean(unsigned char* theBoolean)
  200.         {
  201.             return !SetBit(theBoolean, 7);
  202.         }
  203.         inline Boolean AtomicClearBoolean(unsigned char* theBoolean)
  204.         {
  205.             return ClearBit(theBoolean, 7);
  206.         }
  207.         inline Boolean AtomicTestBoolean(unsigned char* theBoolean)
  208.         {
  209.             return TestBit(theBoolean, 7);
  210.         }
  211.  
  212.     #else
  213.  
  214.         #define AtomicSetBoolean(theBoolean)    !SetBit(theBoolean, 7)
  215.         #define AtomicClearBoolean(theBoolean)    ClearBit(theBoolean, 7)
  216.         #define AtomicTestBoolean(theBoolean)    TestBit(theBoolean, 7)
  217.  
  218.     #endif
  219. #endif
  220.  
  221. /******************************************************************************
  222. ** Memory Functions
  223. **
  224. ** SLMmemcpy, SLMmemmove, and SLMmemset are equivalent to the C memcpy, memmove,
  225. ** and memset routines. They are exported by SLM and are faster then the C versions.
  226. *******************************************************************************/
  227.  
  228. void    ZeroMem(void* dest, size_t nBytes);
  229. void*     SLMmemcpy(void* dest, const void* src, size_t nBytes);
  230. void*     SLMmemmove(void* dest, const void* src, size_t nBytes);
  231. void*    SLMmemset (void *dest, int c, size_t n);
  232.  
  233. /**********************************************************************
  234. ** struct TFileSpec
  235. **
  236. ** TFileSpec is a struct for specifying the location of a library
  237. ** file (TLibraryFile) in a file system or OS independent way. The 
  238. ** "subclasses" contain the details and the "base class" is used to compare
  239. ** them or to pass them around without worry about the contents.
  240. **
  241. ** Currently only the TMacFileSpec is supported since this is how the
  242. ** SLM tracks library files on the Mac OS. There is a chance that in the
  243. ** furture it may track files under System 7.0 using TFileIDFileSpec so
  244. ** you should write your 7.0 code to handle either type. The
  245. ** IsFileSpecTypeSupported() routine will tell you if the specified
  246. ** TFileSpec subclass is supported.
  247. **
  248. ** Generally you don't need to be concerned with with TFileSpecs unless
  249. ** you are going to call RegisterLibraryFile(), RegisterLibraryFileFolder(),
  250. ** or GetFileSpec().
  251. ***********************************************************************/
  252.  
  253. /* Different types of TFileSpecs we can have. */
  254.  
  255. #ifndef __cplusplus
  256.  
  257. typedef unsigned int    FileSpecType;
  258.  
  259. #define kUnknownType    ((FileSpecType)0)
  260. #define kMacType        ((FileSpecType)1)
  261. #define kFileIDType        ((FileSpecType)2)
  262. #define kImageType        ((FileSpecType)3)
  263. #define kMacRomType        ((FileSpecType)9)
  264. #define kMaxType        ((FileSpecType)255)
  265.  
  266. Boolean IsFileSpecTypeSupported(FileSpecType);
  267. Boolean CompareFileSpecs(const void* f1, const void* f2);
  268.  
  269. struct TFileSpec
  270. {
  271.     unsigned char    fType;        /* FileSpectype */
  272.     unsigned char    fSize;        /* size of struct */
  273. };
  274. typedef struct TFileSpec TFileSpec;
  275.  
  276. /**********************************************************************
  277. ** struct TMacFileSpec
  278. **
  279. ** TMacFileSpec keeps track of the file by using an file name, volume
  280. ** refNum, and directory id. You must use InitMacFileSpec to make
  281. ** sure that the length is set properly.
  282. ***********************************************************************/
  283.  
  284. struct TMacFileSpec
  285. {
  286.     unsigned char    fType;        /* FileSpec type                        */
  287.     unsigned char    fSize;        /* size of struct                        */
  288.     short            fVRefNum;    /* volume refNum of volume file is on    */
  289.     long            fParID;        /* dirID of the folder file is in        */
  290.     Str63            fName;        /* name of the file                        */
  291. };        
  292. typedef struct TMacFileSpec TMacFileSpec;
  293.     
  294. void InitMacFileSpec(TMacFileSpec *spec, int vRefNum, long parID, Str63 name);
  295.  
  296. /**********************************************************************
  297. ** struct TFileIDFileSpec
  298. **
  299. ** TFileIDFileSpec keeps track of library files by fileID and vRefNum.
  300. ** You must use InitFileIDFileSpec to make sure that the length is set
  301. ** properly
  302. ***********************************************************************/
  303.  
  304. /* Some macros to make accessing fields without doing a cast easier */
  305. #define GetFileIDFromFileSpec(x)    (((const TFileIDFileSpec*)x)->fFileID)
  306. #define GetVRefNumFromFileSpec(x)    (((const TFileIDFileSpec*)x)->fVRefNum)
  307.  
  308. struct TFileIDFileSpec
  309. {
  310.     unsigned char    fType;        /* FileSpec type    */
  311.     unsigned char    fSize;        /* size of struct    */
  312.     short            fVRefNum;    /* volume refNum    */
  313.     long            fFileID;    /* FileID            */
  314. };
  315. typedef struct TFileIDFileSpec TFileIDFileSpec;
  316.  
  317. void InitFileIDFileSpec(TFileIDFileSpec *spec, int vRefNum, long fileID);
  318.  
  319. #endif
  320.  
  321. /*******************************************************************************
  322. ** RegisterLibraryFile/UnregisterLibraryFile
  323. **
  324. ** Used to register or unregister a library file. Currently only the
  325. ** TMacFileSpec is supported. You'll get a kASLMNotSupportedErr error for anything else.
  326. **
  327. ** RegisterLibraryFile returns kNoError if successful or kASLMFileNotFoundErr if
  328. ** an error ocurred while trying to access the file. Other error codes are also
  329. ** possible if there was trouble processing the file such as kASLMOutOfMemoryErr. If
  330. ** created the TLibraryFile is returned in the TLibraryFile** parameter. You
  331. ** can pass in null if you don't want the value returned.
  332. **
  333. ** UnregisterLibraryFile accepts a "forceUnload" parameter. If true is passed
  334. ** then it will force all loaded libraries in the library file to be
  335. ** unloaded even if they are in use. Unless you are sure that loaded libraries
  336. ** can be safely unloaded you should pass false. In this case the library file
  337. ** will not be deleted until all of its libraries are unloaded.
  338. ** kNoError will be returned if successful and wil be returend kASLMNotSupportedErr if
  339. ** the folder was never registered.
  340. ********************************************************************************/
  341.  
  342. OSErr    RegisterLibraryFile(const TFileSpec*, TLibraryFile**);
  343. OSErr    UnregisterLibraryFile(TLibraryFile*, BooleanParm forceUnload);
  344. OSErr    UnregisterLibraryFileByFileSpec(const TFileSpec*, BooleanParm forceUnload);
  345.  
  346. /*******************************************************************************
  347. ** RegisterLibraryFileFolder/UnregisterLibraryFileFolder
  348. **
  349. ** Used to register a folder that contains library files in it. The SLM will keep
  350. ** track of library files dragged into and out of this folder. Currently only the
  351. ** TMacFileSpec is supported. You'll get a kASLMNotSupportedErr error for anything else.
  352. **
  353. ** RegisterLibraryFileFolder returns kNoError if successful or kASLMFileNotFoundErr if
  354. ** an error ocurred while trying to access the folder.
  355. **
  356. ** UnregisterLibraryFileFolder accepts a "forceUnload" parameter. If true is passed
  357. ** then it will unregister the folder and force all loaded libraries to be
  358. ** unloaded even if they are in use. Unless you are sure that loaded libraries
  359. ** can be safely unloaded you should pass false. kNoError will be returned if
  360. ** successful, kASLMFolderNotFoundErr if the folder was never registered, and
  361. ** kASLMFolderInUseErr if any libraries in the folder were loaded and false was passed
  362. ** in the forceUnload parameter.
  363. ********************************************************************************/
  364.  
  365. OSErr    RegisterLibraryFileFolder(const TFileSpec*);
  366. OSErr    UnregisterLibraryFileFolder(const TFileSpec*, BooleanParm forceUnload);
  367.  
  368. /*******************************************************************************
  369. ** UnloadUnusedLibraries
  370. **
  371. ** UnloadUnusedLibraries forces any libraries the are currently scheduled to
  372. ** be unloaded (because they are no longer being used) to be unloaded immediately
  373. ** rather then letting ASLM wait up to 1 second before unloading them. This
  374. ** routine is rarely needed, but may be necessary if you have complex library
  375. ** dependencies and are having trouble getting your libraries to unload.
  376. ********************************************************************************/
  377.  
  378. void    UnloadUnusedLibraries(void);
  379.  
  380. /*******************************************************************************
  381. ** EnterSystemMode/LeaveSystemMode
  382. **
  383. ** These functions should bracket calls that open files or get memory that needs
  384. ** to hang around after an application quits
  385. ********************************************************************************/
  386.  
  387. void*    EnterSystemMode(void);
  388. void    LeaveSystemMode(void*);
  389.  
  390. /*******************************************************************************
  391. ** Death Notification
  392. ********************************************************************************/
  393.  
  394. Boolean InstallDeathWatcher(TNotifier* notifier);
  395. Boolean RemoveDeathWatcher(TNotifier* notifier);
  396.  
  397. /*******************************************************************************
  398. ** EnterInterrupt/LeaveInterrupt
  399. **
  400. ** These functions should be called when you are in an interrupt service routine
  401. ** or a deferred task and you want to do something that will cause ASLM
  402. ** code to be executed such as allocating pool memory or newing an object. The
  403. ** ASLM needs to know that it is at interrupt time so it doesn't do
  404. ** anything stupid like try to allocate memory or load library code. This doesn't
  405. ** mean that all ASLM calls are safe at interrupt time, just that the
  406. ** ones that claim to be safe will only be safe if you do an EnterInterrupt call
  407. ** first.
  408. **
  409. ** You don't need to use these routines when your interrupt service routine is
  410. ** scheduling an operation on a TInterruptScheduler, when the operation gets
  411. ** executed at deferred task time, or when a TTimeScheduler operation gets
  412. ** executed. In the former case the ASLM is smart enough to realize
  413. ** that you are at interrupt time and in the later two cases the
  414. ** ASLM does an EnterInterrupt before calling your operation and a
  415. ** LeaveInterrupt when your operation returns.
  416. ********************************************************************************/
  417.  
  418. void    EnterInterrupt(void);
  419. void    LeaveInterrupt(void);
  420.  
  421. /*******************************************************************************
  422. ** AtInterruptLevel
  423. **
  424. ** This function returns true if we are currently executing at non-system-task
  425. ** time.
  426. ********************************************************************************/
  427.  
  428. Boolean AtInterruptLevel(void);
  429.  
  430. /*******************************************************************************
  431. ** InInterruptScheduler
  432. **
  433. ** This function returns true if we are currently running an interrupt scheduler
  434. ********************************************************************************/
  435.  
  436. Boolean InInterruptScheduler(void);
  437.  
  438. /**********************************************************************
  439. ** GlobalWorld routines
  440. **
  441. ** InitGlobalWorld will create and initialize the global world for
  442. ** standalone code on the MacOS such as INITs and CDEVs. It also does
  443. ** a SetCurrentGlobalWorld. FreeGlobalWorld will free the memory used
  444. ** by the global world created by InitGlobalWorld.
  445. **
  446. ** EnterCodeResource is also used by stand alone code resources. It is
  447. ** most useful when the code resource only calls InitLibraryManager once
  448. ** but may then be reentered multiple times before calling CleanupLibraryManager.
  449. ** EnterCodeResoruce will set the current global world to the code resources
  450. ** global world and set the code resource as the current client.
  451. ** LeaveCodeResource will undo what EnterCodeResource does. These routines
  452. ** are NOT reentrant. You must call InitCodeResource before calling
  453. ** EnterCodeResource. It will call InitGlobalWorld and save the global world
  454. ** pointer in a PC-relative location so EnterCodeResource can access it.
  455. **
  456. ** SetCurrentGlobalWorld and GetCurrentGlobalWorld used for getting and
  457. ** setting A5 on the MacOS.
  458. **
  459. ** GetGlobalWorld is used to get the global world pointer for a Library.
  460. ** OpenGlobalWorld will make the library's global world the current global
  461. ** world. It's the same as calling SetCurrentGlobalWorld(GetGlobalWorld()).
  462. ** CloseGlobalWorld is used to revert back to the global world that was
  463. ** current before calling OpenGlobalWorld. It's the same as calling
  464. ** SetCurrentGlobalWorld(oldWorld) except that it doesn't return a
  465. ** global world.
  466. **
  467. ** Since libraries are always compiled with model far, it's
  468. ** not necessary to do an OpenGlobalWorld before accessing globals or
  469. ** making intersegment calls. Their only purpose is to make the library
  470. ** the current "Client" since the client is determined by the current
  471. ** value of A5 on the MacOS.
  472. **
  473. ** ONLY LIBRARIES AND MODEL FAR CLIENTS SHOULD CALL Get/Open/CloseGlobalWorld.
  474. ********************************************************************************/
  475.  
  476. GlobalWorld ASLMGetCurrentGlobalWorld(void);
  477. GlobalWorld ASLMSetCurrentGlobalWorld(GlobalWorld newWorld);
  478.  
  479. #if USES68KINLINES
  480.  
  481.     #pragma parameter __D0 SetCurrentGlobalWorld(__A0)
  482.     GlobalWorld SetCurrentGlobalWorld(GlobalWorld newWorld)
  483.         = {0x200D,                        /* move.l    A5,D0        */
  484.            0x2A48};                        /* move.l    A0,A5        */
  485.            
  486.     GlobalWorld GetCurrentGlobalWorld()
  487.         = {0x200D};                        /* move.l    A5,D0        */
  488.  
  489. #else
  490.  
  491.     #define GetCurrentGlobalWorld ASLMGetCurrentGlobalWorld
  492.     #define SetCurrentGlobalWorld ASLMSetCurrentGlobalWorld
  493.  
  494. #endif
  495.  
  496.  
  497. OSErr                InitGlobalWorld(void);        /* called by standalone code only!!! */
  498. void                FreeGlobalWorld(void);        /* called by standalone code only!!! */
  499.  
  500. OSErr                InitCodeResource(void);        /* called by standalone code only!!! */
  501. void                EnterCodeResource(void);    /* called by standalone code only!!! */
  502. void                LeaveCodeResource(void);    /* called by standalone code only!!! */
  503.     
  504. TLibraryManager*    GetCurrentClient(void);
  505. TLibraryManager*    GetSystemClient(void);        /* returns the ASLM client */
  506. TLibraryManager*    GetLibraryClient(TLibrary*);/* returns the library's client */
  507.  
  508. TLibraryManager*    SetCurrentClient(TLibraryManager*);
  509. TLibraryManager*    SetSelfAsClient(void);        /* set owner of code making call as current client */
  510. TLibraryManager*    SetSystemAsClient(void);    /* set ASLM itself as current client */
  511. #if GENERATING68K
  512. TLibraryManager*    SetClientToWorld(void);        /* set owner of current global world as current client */
  513. TLibraryManager*    GetClientFromWorld(GlobalWorld);    /* get client which owns the specified global world */
  514. #endif
  515.     
  516. GlobalWorld     GetGlobalWorld(void);
  517. GlobalWorld        OpenGlobalWorld(void);
  518. void            CloseGlobalWorld(GlobalWorld oldWorld);
  519.  
  520. /*    -------------------------------------------------------------------------
  521.     Inline implementation for global world functions
  522.     ------------------------------------------------------------------------- */
  523.  
  524. #ifdef __cplusplus
  525.     inline GlobalWorld GetGlobalWorld()
  526.     {
  527.         return GetLocalLibraryManager()->GetGlobalWorld();
  528.     }
  529.     inline GlobalWorld OpenGlobalWorld()
  530.     {
  531.         return SetCurrentGlobalWorld(GetGlobalWorld());
  532.     }
  533.     inline void    CloseGlobalWorld(GlobalWorld oldWorld)
  534.     {
  535.         SetCurrentGlobalWorld(oldWorld);
  536.     }
  537. #else
  538.     #define GetGlobalWorld()        ((GlobalWorld)(((void**)GetLocalLibraryManager())[4]))
  539.     #define OpenGlobalWorld()        SetCurrentGlobalWorld(GetGlobalWorld())
  540.     #define CloseGlobalWorld(world)    SetCurrentGlobalWorld(world)
  541. #endif
  542.  
  543. /**********************************************************************
  544. ** TLibraryFile "C" interface
  545. **
  546. ** The C interface to the TLibraryFile class defined in 
  547. ** LibraryManagerClasses.h. Used mainly to get resources out of a library.
  548. ********************************************************************************/
  549.  
  550. TLibraryFile*    GetLocalLibraryFile();
  551.  
  552. Ptr            GetSharedResource(TLibraryFile*, ResType, int theID, OSErr*);
  553. Ptr            GetSharedIndResource(TLibraryFile*, ResType, int index, OSErr*);
  554. Ptr            GetSharedNamedResource(TLibraryFile*, ResType,
  555.                                    const char* name, OSErr*);
  556.  
  557. void        ReleaseSharedResource(TLibraryFile*, Ptr);
  558. long        CountSharedResources(TLibraryFile*, ResType);
  559.  
  560. size_t        GetSharedResourceUseCount(TLibraryFile*, Ptr);
  561. OSErr        GetSharedResourceInfo(TLibraryFile*, Ptr, size_t* theSize,
  562.                                   short* theID, ResType*, char* theName);
  563.  
  564. TFileSpec*    GetFileSpec(TLibraryFile*);
  565. long        GetRefNum(TLibraryFile*);
  566.  
  567. OSErr        OpenLibraryFile(TLibraryFile*);
  568. OSErr        CloseLibraryFile(TLibraryFile*);
  569.         
  570. OSErr        Preflight(TLibraryFile*, long* savedRefNum);
  571. OSErr        Postflight(TLibraryFile*, long savedRefNum);
  572.  
  573. /**********************************************************************
  574. ** Miscellaneous TLibrary routines.
  575. ***********************************************************************/
  576.  
  577. TLibraryFile*    GetLibraryFile(TLibrary*);
  578.  
  579. #ifdef __cplusplus
  580.     TLibraryID* GetLibraryID(TLibrary*);
  581. #else
  582.     TLibraryID GetLibraryID(TLibrary*);
  583. #endif
  584.  
  585. /**********************************************************************
  586. ** Routines for loading and unloading library code segments.
  587. ***********************************************************************/
  588.  
  589. #if GENERATING68K
  590. OSErr    LoadCodeSegmentByNumber(TLibrary*, int segmentNumber);
  591. OSErr    LoadCodeSegmentByName(TLibrary*, CDECLProcPtr theRoutine);
  592. OSErr    UnloadCodeSegmentByNumber(TLibrary*, int segmentNumber);
  593. OSErr    UnloadCodeSegmentByName(TLibrary*, CDECLProcPtr theRoutine);
  594. #endif
  595.  
  596. /*********************************************************************
  597. ** Routines that will get a TLibrary object
  598. **********************************************************************/
  599.  
  600. #ifdef __cplusplus
  601.  
  602. TLibrary*    GetLocalLibrary();
  603. TLibrary*    LookupLibrary(const TLibraryID&);
  604. TLibrary*    LookupLibraryWithClassID(const TClassID&);
  605. TLibrary*    LookupLibraryWithFunctionSetID(const TFunctionSetID&);
  606.  
  607. #else
  608.     
  609. TLibrary*    GetLocalLibrary();
  610. TLibrary*    LookupLibrary(const TLibraryID);
  611. TLibrary*    LookupLibraryWithClassID(const TClassID);
  612. TLibrary*    LookupLibraryWithFunctionSetID(const TFunctionSetID);
  613.  
  614. #endif
  615.  
  616. /*********************************************************************
  617. ** Routines for getting all libraries and library files.
  618. **
  619. ** CreateLibraryIterator returns an iterator that will iterate over all
  620. ** publicly known libraries and CreateLibraryFileIterator will return
  621. ** an iterator that will iterate over all publicly known library files.
  622. ** Make sure you delete the iterator when you are done.
  623. **********************************************************************/
  624.  
  625. TIterator* CreateLibraryIterator(TLibraryManager* mgr);
  626. TIterator* CreateLibraryFileIterator(TLibraryManager* mgr);
  627.  
  628. /*********************************************************************
  629. ** Per Client data routines
  630. **********************************************************************/
  631.  
  632. void*    GetClientData(void);
  633. void*    GetLibraryClientData(TLibrary*);
  634.  
  635. /**********************************************************************
  636. ** TClassInfo "C" interface
  637. **
  638. ** The C interface to the TClassInfo class. Used mainly to get information
  639. ** about function sets. It is most useful for iterating over all function sets
  640. ** with a common interface. This can be done by giving the functions sets the
  641. ** same "parent id" when exporting each function set.
  642. **
  643. ** Note, TClassInfo can also be used to iterate over function sets and
  644. ** the routines given below can also be used iterate over classes.
  645. ***********************************************************************/
  646.  
  647. #ifdef __cplusplus
  648.  
  649. TFunctionSetInfo*    GetFunctionSetInfo(const TFunctionSetID&, OSErr* = NULL);
  650. void                FreeFunctionSetInfo(TFunctionSetInfo*);
  651.  
  652. void                FSInfoReset(TFunctionSetInfo*);        // start iteration over
  653. TFunctionSetID*        FSInfoNext(TFunctionSetInfo*);        // get next function set
  654. Boolean                FSInfoIterationComplete(TFunctionSetInfo*);    // true if we are done iterating
  655.  
  656. TFunctionSetID*        FSInfoGetFunctionSetID(TFunctionSetInfo*);
  657. TFunctionSetID*        FSInfoGetInterfaceID(TFunctionSetInfo*, size_t idx = 0);
  658. TLibrary*            FSInfoGetLibrary(TFunctionSetInfo*);
  659. TLibraryFile*        FSInfoGetLibraryFile(TFunctionSetInfo*);
  660. unsigned short        FSInfoGetVersion(TFunctionSetInfo*);
  661. unsigned short        FSInfoGetMinVersion(TFunctionSetInfo*);
  662.  
  663. #else
  664.  
  665. TFunctionSetInfo*    GetFunctionSetInfo(TFunctionSetID, OSErr*);
  666. void                FreeFunctionSetInfo(TFunctionSetInfo*);
  667.  
  668. void                FSInfoReset(TFunctionSetInfo*);        /* start iteration over */
  669. TFunctionSetID        FSInfoNext(TFunctionSetInfo*);        /* get next function set */
  670. Boolean                FSInfoIterationComplete(TFunctionSetInfo*);    /* true if we are done iterating */
  671.  
  672. TFunctionSetID        FSInfoGetFunctionSetID(TFunctionSetInfo*);
  673. TFunctionSetID        FSInfoGetInterfaceID(TFunctionSetInfo*, size_t idx);
  674. TLibrary*            FSInfoGetLibrary(TFunctionSetInfo*);
  675. TLibraryFile*        FSInfoGetLibraryFile(TFunctionSetInfo*);
  676. unsigned short        FSInfoGetVersion(TFunctionSetInfo*);
  677. unsigned short        FSInfoGetMinVersion(TFunctionSetInfo*);
  678.  
  679. #endif
  680.  
  681. /*******************************************************************************
  682. ** Debugging Macros and inlines
  683. ********************************************************************************/
  684.  
  685. void DebugBreakProc(BooleanParm, const char*);
  686.  
  687. #ifdef __cplusplus
  688. }
  689.  
  690. inline void DoDebugBreak(BooleanParm value, const char* str)
  691. {
  692.     DebugBreakProc(value, str);
  693. }
  694.  
  695. inline void DoDebugBreak(const char* str)
  696. {
  697.     DebugBreakProc(true, str);
  698. }
  699.  
  700.  
  701. #define ForceDebugBreak(str)        DoDebugBreak(true, str)
  702.  
  703. #if qDebug
  704.     #define DebugBreak(str)            DoDebugBreak(true, str)
  705.     #define DebugTest(val, str)        DoDebugBreak(val, str)
  706. #else
  707.     #define DebugBreak(str)
  708.     #define DebugTest(val, str)
  709. #endif
  710.  
  711. #else
  712.  
  713. #if qDebug
  714.     #define DebugBreak(str)            DebugBreakProc(true, str)
  715.     #define DebugTest(val, str)        DebugBreakProc(val, str)
  716. #else
  717.     #define DebugBreak(str)
  718.     #define DebugTest(val, str)
  719. #endif
  720.  
  721. #endif
  722.  
  723. /*******************************************************************************
  724. ** TAtomicBoolean
  725. **
  726. ** Set returns true if you were the "setter".
  727. ** Clear returns true if you were the "clearer".
  728. ** Test returns the current state of the boolean.
  729. ********************************************************************************/
  730.  
  731. #ifdef __cplusplus
  732.  
  733. struct TAtomicBoolean
  734. {
  735.         void        Init();
  736.         Boolean        Set();
  737.         Boolean        Clear();
  738.         Boolean        Test();
  739.         
  740.     unsigned char    fFlag;
  741. };
  742.  
  743.     inline void TAtomicBoolean::Init()
  744.     {
  745.         fFlag = 0;
  746.     }
  747.  
  748.     inline Boolean TAtomicBoolean::Set()
  749.     {
  750.         return AtomicSetBoolean(&fFlag);
  751.     }
  752.  
  753.     inline Boolean TAtomicBoolean::Clear()
  754.     {
  755.         return AtomicClearBoolean(&fFlag);
  756.     }
  757.     
  758.     inline Boolean TAtomicBoolean::Test()
  759.     {
  760.         return AtomicTestBoolean(&fFlag);
  761.     }
  762.  
  763. #endif    
  764.  
  765. /*******************************************************************************
  766. ** TUseCount
  767. ********************************************************************************/
  768.  
  769. #ifdef __cplusplus
  770.  
  771. #if USES68KINLINES
  772.  
  773.     #pragma parameter __D0 IncrementUseCount(__A0)
  774.     extern "C" Boolean IncrementUseCount(long*) =
  775.     {
  776.         0x5290,        /*    addq.l    #1,(a0)    */
  777.         0x57c0        /*  seq        d0        */
  778.     };
  779.     
  780.     #pragma parameter __D0 DecrementUseCount(__A0)
  781.     extern "C" Boolean DecrementUseCount(long*) =
  782.     {
  783.         0x5390,        /*    subq.l    #1,(a0)    */
  784.         0x5bc0        /*  smi        d0        */
  785.     };
  786.  
  787. #else
  788.  
  789.     extern "C" Boolean IncrementUseCount(long*);
  790.     extern "C" Boolean DecrementUseCount(long*);
  791.  
  792. #endif
  793.  
  794. struct TUseCount
  795. {
  796.         void        SetValue(long);
  797.         void        SetUseCount(long);
  798.         long        GetValue() const;
  799.         long        GetUseCount() const;
  800.         void        Init();
  801.         Boolean        Increment();        // Returns True if first time
  802.         Boolean        Decrement();        // Returns True if back to unused
  803.         Boolean        IsUnused() const;
  804.         
  805.     long    fValue;
  806. };
  807.  
  808. /*    -------------------------------------------------------------------------
  809.     Inline methods for TUseCount
  810.     ------------------------------------------------------------------------- */
  811.  
  812.     inline void TUseCount::SetValue(long val)
  813.     {
  814.         fValue = val;
  815.     }
  816.     
  817.     inline void TUseCount::SetUseCount(long val)
  818.     {
  819.         fValue = val - 1;
  820.     }
  821.     
  822.     inline void TUseCount::Init()
  823.     {
  824.         fValue = -1;
  825.     }
  826.     
  827.     inline Boolean TUseCount::IsUnused() const
  828.     {
  829.         return fValue < 0;
  830.     }
  831.     
  832.     inline long TUseCount::GetValue() const
  833.     {
  834.         return fValue;
  835.     }
  836.     
  837.     inline long TUseCount::GetUseCount() const
  838.     {
  839.         return fValue + 1;
  840.     }
  841.     
  842.     inline Boolean TUseCount::Increment()
  843.     {
  844.         return IncrementUseCount(&fValue);
  845.     }
  846.     
  847.     inline Boolean TUseCount::Decrement()
  848.     {
  849.         return DecrementUseCount(&fValue);
  850.     }
  851.     
  852. #endif    
  853.  
  854. #endif
  855.